require "ttWxCommon"
##############################################################################################
#
##############################################################################################
##############################################################################################
#
##############################################################################################
class MainToolBarMgr
	def initialize(frm)
		@frame = frm
		@mainToolBar = @frame.get_tool_bar()
		@offset = 10
		@iconPath = $globalTTPathRubyResource +"/16x16icons"
		@bm = {}
		self.loadBitMaps()
		nextPos=Point.new(@offset,0)
		@targetChoise = MainToolBarTarget.new(@mainToolBar,nextPos)
		@mainToolBar.add_separator
		@offset = @offset + @targetChoise.get_client_size.get_width + 10
		nextPos=Point.new(@offset,0)
		@configChoise = MainToolBarConfig.new(@mainToolBar,nextPos)
	end
	def reloadProject()
		self.loadTargetChoice()
		self.loadConfigChoice()
	end

	def getCurrentConfig()
		selected = @configChoise.get_selection()
		if NOT_FOUND != selected then
			return @configChoise.get_item_data(selected)
		end
		return nil
	end
##############################################################################################
#
##############################################################################################
	def loadTargetChoice()
		targets = $globalProjectMgr.getTargets()
		if not targets or not @targetChoise then
			return 
		end
		@targetChoise.clear
		curTarget = $globalProjectMgr.getCurTarget()
		@curTargetChoiseID = nil
		if curTarget then
			@curTargetChoiseID = curTarget.get_text
		end
		targets.each_element do |target|
			myName = target.attributes["name"]
			myType = target.attributes["type"]
			mydata = target.attributes["id"]
			if myName and myType and mydata then
				if @bm[myType] then
#					item = @targetChoise.append(myName,@bm[myType],mydata)
					item = @targetChoise.append(myName,mydata)
				else
#					item = @targetChoise.append(myName,NULL_BITMAP,mydata)
					item = @targetChoise.append(myName,mydata)
				end
			end
			if nil == @curTargetChoiseID then
				@curTargetChoiseID = mydata
			end
			if item and @curTargetChoiseID == mydata then
				@targetChoise.select(item)
			end
		end
	end
	def loadConfigChoice()
		configs = $globalProjectMgr.getConfigs()
		if not configs or not @configChoise then
			return 
		end
		@configChoise.clear
		curConfig = $globalProjectMgr.getCurConfig()
		@curConfChoiseID = nil
		if curConfig then
			@curConfChoiseID = curConfig.get_text
		end
		configs.each_element do |config|
			myName = config.attributes["name"]
			mydata = config.attributes["id"]
			if myName and mydata then
#				item = @configChoise.append(myName,NULL_BITMAP,mydata)
				item = @configChoise.append(myName,mydata)
#				@configChoise.set_item_data(item,mydata)
			end
			if nil == @curConfChoiseID then
				@curConfChoiseID = mydata
			end
			if item and @curConfChoiseID == mydata then
				@configChoise.select(item)
			end
		end
	end
	def loadBitMaps()
		bm = Bitmap.new
		bm.load_file(@iconPath+"/execute.png",BITMAP_TYPE_PNG)
		@bm["execute"] = bm

		bm = Bitmap.new
		bm.load_file(@iconPath+"/staticLib.png",BITMAP_TYPE_PNG)
		@bm["static"] = bm

		bm = Bitmap.new
		bm.load_file(@iconPath+"/sharedLib.png",BITMAP_TYPE_PNG)
		@bm["shared"] = bm
	end
end

#class MainToolBarTarget < BitmapComboBox
class MainToolBarTarget < ComboBox
	def initialize(bar,pos)
		@bar = bar
		super(@bar, ID_ANY,"", pos, Size.new(100,-1))
		@bar.add_control(self)
	end
end

#class MainToolBarConfig < BitmapComboBox
class MainToolBarConfig < ComboBox
	def initialize(bar,pos)
		@bar = bar
		super(@bar, ID_ANY,"" ,pos, Size.new(100,-1))
		@bar.add_control(self)
	end
end
